// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ScrollBar.java

package mForms;

import javax.microedition.lcdui.Graphics;

public final class ScrollBar
{

    public ScrollBar(int w, int h)
    {
        width = w;
        height = h;
        if(width <= 128)
            bar_size = 6;
        else
        if(width >= 350)
            bar_size = 10;
        else
            bar_size = 8;
        h1 = height - 1;
        x = width - bar_size;
        y = 0;
        h2 = height;
    }

    public void setNumLines(int i)
    {
        try
        {
            num_lines = i;
            cur_line = 1;
            y_bar = 0;
            bar_height = (height - 8) / num_lines + 8;
        }
        catch(Exception exception) { }
    }

    public int getBarSize()
    {
        return bar_size;
    }

    public final void inc()
    {
        if(cur_line + 1 > num_lines + 1)
        {
            return;
        } else
        {
            cur_line++;
            return;
        }
    }

    public final void set(int i)
    {
        if(i + 1 > num_lines + 1)
        {
            return;
        } else
        {
            cur_line = i;
            return;
        }
    }

    public final void dec()
    {
        if(cur_line - 1 <= 0)
        {
            return;
        } else
        {
            cur_line--;
            return;
        }
    }

    public final void reset(boolean flag)
    {
        cur_line = 1;
    }

    public boolean isInsideBar(int i, int j)
    {
        return i >= x && j >= y_bar && j <= y_bar + bar_height;
    }

    public boolean isInside(int i, int j)
    {
        return i >= x;
    }

    public int getLineFromY(int i)
    {
        if(num_lines == 1)
            return 1;
        if(i >= height)
            return num_lines;
        if(i <= 0)
            return 1;
        if(i >= y_bar && i <= y_bar + bar_height || i >= height)
            return cur_line;
        int j = (i * num_lines) / h2 + 1;
        if(j > num_lines)
            j = num_lines;
        return j;
    }

    public void draw(Graphics g)
    {
        g.setColor(0xffffff);
        g.fillRect(x, y, bar_size - 1, h1);
        g.setColor(0);
        g.drawRect(x, y, bar_size - 1, h1);
        bar_height = h2 / num_lines;
        if(cur_line - 1 <= 0)
            y_bar = 0;
        else
            y_bar = ((cur_line - 1) * h2) / num_lines;
        if(y_bar + bar_height > h1)
            bar_height = h1 - y_bar;
        g.drawRect(x, y_bar, bar_size, bar_height);
        g.setColor(0xcccccc);
        g.fillRect(x + 1, y_bar + 1, bar_size - 2, bar_height - 1);
        g.setColor(0);
        int i = y_bar + (bar_height >> 1);
        g.drawLine(x + 2, i, (x + bar_size) - 3, i);
        if(i - 2 > y_bar + 1)
        {
            g.drawLine(x + 2, i - 2, (x + bar_size) - 3, i - 2);
            g.drawLine(x + 2, i + 2, (x + bar_size) - 3, i + 2);
        }
    }

    private int x;
    private int y;
    private int bar_size;
    private int h1;
    private int y_bar;
    private int bar_height;
    private int h2;
    private int num_lines;
    private int cur_line;
    private int height;
    private int width;
}
